//
//  YFNearCategoryView.m
//  QuanJieShopProject
//
//  Created by apple on 2018/5/30.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFNearCategoryView.h"

@implementation YFNearCategoryView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self makeView];
    }
    return self;
}



- (void)makeView {
    
#warning 这里需要优化下
    // 60*68
    CGFloat btnW = UISCREEN_WIDTH/5;
    CGFloat btnH = btnW * 180.f/160.f;
    
    [self createBtnWithTitle:@"美食" imgStr:@"ms_near" frame:CGRectMake(0, 0, btnW, btnH) tag:YFNearTagFood];
    [self createBtnWithTitle:@"休闲娱乐" imgStr:@"xxyl_near" frame:CGRectMake(btnW, 0, btnW, btnH) tag:YFNearTagEntertainment];
    [self createBtnWithTitle:@"生鲜果蔬" imgStr:@"sxgs_near" frame:CGRectMake(btnW*2, 0, btnW, btnH) tag:YFNearTagFruit];
    [self createBtnWithTitle:@"K歌" imgStr:@"kSong_near" frame:CGRectMake(btnW*3, 0, btnW, btnH) tag:YFNearTagSong];
    [self createBtnWithTitle:@"酒店住宿" imgStr:@"jdzs_near" frame:CGRectMake(btnW*4, 0, btnW, btnH) tag:YFNearTagHotel];

    // 50*50
    CGFloat padding = 20;
    CGFloat subBtnW = (UISCREEN_WIDTH - 2*padding)/5;
    CGFloat subBtnH = subBtnW;
    [self createSubBtnWithTitle:@"足浴/按摩" imgStr:@"zy_near" frame:CGRectMake(padding, btnH, subBtnW, subBtnH) tag:YFNearTagMassage];
    [self createSubBtnWithTitle:@"丽人/美发" imgStr:@"mf_near" frame:CGRectMake(padding + subBtnW, btnH, subBtnW, subBtnH) tag:YFNearTagHair];
    [self createSubBtnWithTitle:@"小吃/快餐" imgStr:@"xc_near" frame:CGRectMake(padding + subBtnW *2, btnH, subBtnW, subBtnH) tag:YFNearTagSnack];
    [self createSubBtnWithTitle:@"甜点/饮品" imgStr:@"yp_near" frame:CGRectMake(padding + subBtnW *3, btnH, subBtnW, subBtnH) tag:YFNearTagSweet];
    [self createSubBtnWithTitle:@"快消/副食" imgStr:@"kx_near" frame:CGRectMake(padding + subBtnW *4, btnH, subBtnW, subBtnH) tag:YFNearTagKX];

    self.height = btnH + subBtnH;
}


- (void)createBtnWithTitle:(NSString *)title imgStr:(NSString *)imgStr frame:(CGRect)frame tag:(NSInteger)tag {
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    btn.tag = tag;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn setTitleColor:YFColor_Text forState:UIControlStateNormal];
    [btn layoutButtonWithEdgeInsetsStyle:LLButtonStyleTextBottom imageTitleSpace:8];
    [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
//    btn.backgroundColor = [UIColor randomColor];
    [self addSubview:btn];
}


- (void)createSubBtnWithTitle:(NSString *)title imgStr:(NSString *)imgStr frame:(CGRect)frame tag:(NSInteger)tag  {
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    btn.tag = tag;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:11];
    [btn setTitleColor:YFColor_Text forState:UIControlStateNormal];
    [btn layoutButtonWithEdgeInsetsStyle:LLButtonStyleTextBottom imageTitleSpace:5];
    [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
//    btn.backgroundColor = [UIColor randomColor];
    [self addSubview:btn];
}


- (void)btnClickAction:(UIButton *)button {
    NSInteger tag = button.tag;
    if (self.buttonClickBlock) {
        self.buttonClickBlock(tag);
    }
}

@end
